package com.weimei.conversionTreasure.viewModel;

import android.app.Activity;
import android.app.Application;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.nfc.tech.NfcA;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.gtdev5.geetolsdk.mylibrary.util.DataSaveUtils;
import com.weimei.conversionTreasure.R;
import com.weimei.conversionTreasure.activity.FeedBackActivity;
import com.weimei.conversionTreasure.activity.LoginActivity;
import com.weimei.conversionTreasure.activity.SetActivity;
import com.weimei.conversionTreasure.activity.VipActivity;
import com.weimei.conversionTreasure.app.AppConfig;
import com.weimei.conversionTreasure.utils.ShapeUtils;
import com.weimei.conversionTreasure.utils.UserUtils;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class TabThreeVM extends BaseViewModel {
    public TabThreeVM(@NonNull Application application) {
        super(application);
    }

    Activity mActivity;
    @Override
    public void setActivity(Activity activity) {
        super.setActivity(activity);
        this.mActivity = activity;
    }

    public BindingCommand lxkf = new BindingCommand(() -> {
        //获取剪贴板管理器：
        ClipboardManager cm = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
        // 创建普通字符型ClipData
        ClipData mClipData = ClipData.newPlainText("qq", "971225201");
        // 将ClipData内容放到系统剪贴板里。
        cm.setPrimaryClip(mClipData);
        ToastUtils.showShort("复制成功");
    });

    public BindingCommand share = new BindingCommand(() -> {
        ShapeUtils.onShape(mActivity,"我发现一个很好用的应用："+mActivity.getString(R.string.appid)+",下载链接：http://www.csweimei.cn/");
    });

    public BindingCommand set = new BindingCommand(() -> startActivity(SetActivity.class));

    public BindingCommand login = new BindingCommand(() -> {
        if (!UserUtils.isLogin()) {
            startActivity(LoginActivity.class);
        }
    });

    public BindingCommand vipClick = new BindingCommand(() -> {
        if (UserUtils.isLogin()) {
            startActivity(VipActivity.class);
        }else {
            startActivity(LoginActivity.class);
        }
    });

    public BindingCommand feed = new BindingCommand(() -> {
        if (UserUtils.isLogin()) {
            startActivity(FeedBackActivity.class);
        }else {
            startActivity(LoginActivity.class);
        }
    });


    public ObservableField<String> name = new ObservableField<>(AppConfig.APP_NAME);
    public ObservableField<String> headImg = new ObservableField<>(AppConfig.APP_NAME);
    public ObservableField<String> userPhone = new ObservableField<>("");
    public ObservableField<String> vipTime = new ObservableField<>("暂未开通VIP服务");


    @Override
    public void onResume() {
        super.onResume();
        if (UserUtils.isLogin()){
            name.set(UserUtils.getUserName());
            headImg.set(UserUtils.getUserImg());
//            userPhone.set(UserUtils.getUserPhone());

            if (DataSaveUtils.getInstance().isVip()){
                vipTime.set("会员到期时间："+DataSaveUtils.getInstance().getVip().getTime());
            }else {
                vipTime.set("暂未开通VIP服务");
            }

            userPhone.set("当前剩余免费次数："+UserUtils.getFreeNum());

        }else {
            name.set("请点击头像登录");
            headImg.set("");
            userPhone.set("请点击头像登录");
            vipTime.set("暂未开通VIP服务");

        }
    }
}
